import 'package:flutter/material.dart';
import 'package:hbtrans_flutter/utils/mydio.dart';

import '../../apis.dart';
import '../../const.dart';

class FeedBack extends StatefulWidget {
  @override
  _FeedBackState createState() => _FeedBackState();
}

class _FeedBackState extends State<FeedBack> {
  TextEditingController _controllerFeed =
      TextEditingController.fromValue(TextEditingValue(text: ''));
  TextEditingController _controllerPhone =
      TextEditingController.fromValue(TextEditingValue(text: ''));

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('意见反馈'),
        backgroundColor: Color(0xff23AFDC),
        centerTitle: true,
      ),
      body: Container(
        color: Color(0xFFFBFBFB),
        child: Column(
          children: <Widget>[
            Container(
              height: 220,
              color: Colors.white,
              child: TextFormField(
                keyboardType: TextInputType.text,
                controller: _controllerFeed,
                style: TextStyle(fontSize: 16, color: Colors.grey),
                maxLines: 11,
                decoration: InputDecoration(
                  border: InputBorder.none,
                  contentPadding: const EdgeInsets.fromLTRB(16, 8, 16, 8),
                  hintText: '请输入意见或问题',
                  hintStyle: TextStyle(color: Color(0xff999999), fontSize: 16),
                ),
                autofocus: false,
              ),
            ),
            SizedBox(
              height: 1,
            ),
            Container(
              height: 40,
              color: Colors.white,
              child: TextFormField(
                keyboardType: TextInputType.number,
                controller: _controllerPhone,
                style: TextStyle(fontSize: 16, color: Colors.grey),
                decoration: InputDecoration(
                  contentPadding: const EdgeInsets.fromLTRB(16, 8, 0, 8),
                  hintText: '请输入联系电话（选填）',
                  border: InputBorder.none,
                  hintStyle: TextStyle(color: Color(0xff999999), fontSize: 16),
                ),
                autofocus: false,
              ),
            ),
            SizedBox(
              height: 65,
            ),
            Padding(
              padding: const EdgeInsets.all(16.0),
              child: MaterialButton(
                height: 40,
                minWidth: MediaQuery.of(context).size.width,
                elevation: 0,
                onPressed: () {
//                String route = '${Routes.msgManager}?pageIndex=$pageIndex';
//                Routes.router.navigateTo(context, route,
//                    replace: true, transition: TransitionType.fadeIn);
                  print(_controllerFeed.text);
                  print(_controllerPhone.text);
                  if (_controllerFeed.text.length == 0) {
                    return;
                  } else if (_controllerPhone.text.length == 0) {
                    return;
                  }
                  Map data = Map<String, dynamic>();
                  data["tel"] = _controllerPhone.text;
                  data["content"] = _controllerFeed.text;
                  MyDio.getInstance(url: Const.TRANS_SERVER_MY_PATH)
                      .get(Apis.saveFeedBack, (data) {
                    print(data);
                    Navigator.pop(context);
                  }, params: data);
                },
                child: Text(
                  "提交",
                  style: TextStyle(color: Colors.white, fontSize: 18),
                ),
                color: Color(0xff23AFDC),
                shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.all(Radius.circular(20))),
              ),
            )
          ],
        ),
      ),
    );
  }
}
